package com.patelski.magic.controller;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateful;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.framework.EntityHome;

import com.patelski.common.controller.AbstractEntityHomeImpl;
import com.patelski.common.controller.StatefulAbstractEntityHomeImpl;
import com.patelski.magic.model.Edition;
import com.patelski.magic.model.Card;
import com.patelski.magic.model.EditionCategorie;

@Stateful
@Name("editionHome")
public class EditionHomeImpl extends StatefulAbstractEntityHomeImpl<Edition>
		implements EditionHome {

	private byte[] uploadExpansionSymbol;

	private String id;

	private EditionCategorie editionCategorie;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Transactional
	public Edition getInstance() {
		return super.getInstance();
		// log.info("EditionHome getInstance: #0", this.instance.getName());
		// return instance;
	}

	@Override
	protected Edition createInstance() {
		this.instance = new Edition();
		return this.instance;
	}

	public byte[] getUploadExpansionSymbol() {
		return uploadExpansionSymbol;
	}

	public void setUploadExpansionSymbol(byte[] uploadExpansionSymbol) {
		if (null != uploadExpansionSymbol) {
			this.instance.setExpansionSymbol(uploadExpansionSymbol);
		}
		this.uploadExpansionSymbol = uploadExpansionSymbol;
	}

	public List<Card> getTheSet() {
		return getInstance() == null ? null : new ArrayList<Card>(getInstance()
				.getTheSet());
	}

	public void addCard(Card card) {
		log.info("Add card #0 to inventory. ", card.getCardName());
		this.addFacesMessage("Add card #0 to inventory. ", card.getCardName());
	}

	public EditionCategorie getEditionCategorie() {
	    return editionCategorie;
    }

	public void setEditionCategorie(EditionCategorie editionCategorie) {
		log.info("Edition categorie set to #0. ", editionCategorie.getName());
		this.editionCategorie = em.merge(editionCategorie);
		if (null != this.editionCategorie) {
			this.instance.setEditionCategorie(this.getEditionCategorie());
		}
    }
}